#!/usr/bin/env python

"""
Helper functions for the euclid vector/point/matrix package
"""
import euclid

def truncate( vec, length ):
    """Assurs that the vector is maximum "length" lang"""
    assert isinstance(vec, euclid.Vector2) or isinstance(vec, euclid.Vector3), "Argument must be a vector"
    if vec.magnitude() > length:
        vec.normalize()
        vec *= length
    return vec

def perp( vec ):
    """Returns a vector2 perpendicular to the argument vector"""
    assert isinstance(vec, euclid.Vector2) , "Argument must be a vector2"
    return euclid.Vector2( -vec.y, vec.x )
    
def zero(vec):
    """Sets all vector components to 0"""
    assert isinstance(vec, euclid.Vector2) or isinstance(vec, euclid.Vector3), "Argument must be a vector"
    vec.x = vec.y = 0
    if len(vec) == 3:
        vec.z = 0
    return vec